home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
L_CHSRC_
/
ANALYSIS.C
< prev
next >
Wrap
Text File
|
1990-01-26
|
14KB
|
558 lines
/********************************************************************************
* analysis.c
*
* Color Pair Analysis Package
*
* Written by Paco Xander Nathan
* ⌐1990, Motorola Inc. Public domain source code.
********************************************************************************/
#include "applic.h"
#include "window.h"
#include "dialog.h"
#include "text.h"
#include "string.h"
#include "test.h"
#include "gnosis.h"
#include "analysis.h"
#define LINEHEIGHT 20
/* External Data Structures
*/
GnosData
analGnosBuf;
/* Local Data Structures
*/
/* Local Function Prototypes
*/
#ifdef PROTOTYPES
#endif
/* Analyze one pass through adjacent color pairings
*/
void
AnalPass (thePass)
register WORD thePass;
{
register WORD i;
for (i = 0; i < MAXPAD; i++) {
analGnosBuf.color[thePass][testPad[i].order] = testPad[i].color - 2 + '0';
if (analGnosBuf.color[thePass][testPad[i].order] == '8')
analGnosBuf.color[thePass][testPad[i].order] = '0';
}
}
/* Score matches between the two passes
*/
void
AnalPairs ()
{
register WORD i, j;
/* Score each testPass1 pair by looking up its identical pair or transpose
* in testPass0
*/
for (i = 0; i < (MAXPAD - 1); i++) {
analGnosBuf.pair[testPass1][i] = prDifferent;
for (j = 0; j < (MAXPAD - 1); j++) {
if ((analGnosBuf.color[testPass1][i] == analGnosBuf.color[testPass0][j]) && (analGnosBuf.color[testPass1][i + 1] == analGnosBuf.color[testPass0][j + 1]))
analGnosBuf.pair[testPass1][i] = prIdentical;
else if ((analGnosBuf.color[testPass1][i] == analGnosBuf.color[testPass0][j + 1]) && (analGnosBuf.color[testPass1][i + 1] == analGnosBuf.color[testPass0][j]))
analGnosBuf.pair[testPass1][i] = prTranspose;
}
}
/* Score each testPass0 pair by looking up its identical pair or transpose
* in testPass1
*/
for (i = 0; i < (MAXPAD - 1); i++) {
analGnosBuf.pair[testPass0][i] = prDifferent;
for (j = 0; j < (MAXPAD - 1); j++) {
if ((analGnosBuf.color[testPass0][i] == analGnosBuf.color[testPass1][j]) && (analGnosBuf.color[testPass0][i + 1] == analGnosBuf.color[testPass1][j + 1]))
analGnosBuf.pair[testPass0][i] = prIdentical;
else if ((analGnosBuf.color[testPass0][i] == analGnosBuf.color[testPass1][j + 1]) && (analGnosBuf.color[testPass0][i + 1] == analGnosBuf.color[testPass1][j]))
analGnosBuf.pair[testPass0][i] = prTranspose;
}
}
analGnosBuf.pair[testPass0][MAXPAD - 1] = prDifferent;
analGnosBuf.pair[testPass1][MAXPAD - 1] = prDifferent;
}
/* Determine the marks for the given color test pass
*/
void
AnalMarks (thePass)
register WORD thePass;
{
register WORD i;
/* Mark all the remaining with '='
*/
for (i = 0; i < MAXPAD; i++)
analGnosBuf.mark[thePass][i] = '=';
/* Last single or pair is '-'
*/
i = MAXPAD - 1;
analGnosBuf.mark[thePass][i--] = '-';
if (analGnosBuf.pair[thePass][i] != prDifferent)
analGnosBuf.mark[thePass][i] = '-';
/* First single or pair is '+'
*/
i = 0;
analGnosBuf.mark[thePass][i] = '+';
if (analGnosBuf.pair[thePass][i] != prDifferent) {
i++;
analGnosBuf.mark[thePass][i] = '+';
}
/* Second single or pair is 'x'; try to use this pair if possible to
* prevent fragmentation...
*/
i++;
analGnosBuf.mark[thePass][i] = 'x';
if (analGnosBuf.pair[thePass][i] != prDifferent) {
i++;
analGnosBuf.mark[thePass][i] = 'x';
}
}
/* Determine the anxiety marks for the given color test pass
*/
void
AnalAngst (thePass)
register WORD thePass;
{
register Boolean xFound = FALSE;
register WORD i, j;
/* Clear the anxiety positions
*/
analGnosBuf.total[thePass] = 0;
for (i = 0; i < MAXPAD; i++) {
analGnosBuf.anxiety[thePass][i] = '╩';
analGnosBuf.stress[thePass][i] = '╩';
}
/* Check for basic colors in the last three positions
*/
for (i = MAXPAD - 3; i < MAXPAD; i++) {
if ((analGnosBuf.color[thePass][i] == '1') || (analGnosBuf.color[thePass][i] == '2') ||
(analGnosBuf.color[thePass][i] == '3') || (analGnosBuf.color[thePass][i] == '4')) {
for (j = i; j < MAXPAD; j++) {
analGnosBuf.mark[thePass][j] = '-';
analGnosBuf.anxiety[thePass][j] = 'A';
}
analGnosBuf.anxiety[thePass][0] = 'C';
analGnosBuf.stress[thePass][i] = i - MAXPAD + '4';
analGnosBuf.total[thePass] += i - MAXPAD + 4;
}
}
/* Check for auxilliary colors in the first three positions
*/
for (i = 0; i < 3; i++) {
if ((analGnosBuf.color[thePass][i] == '6') || (analGnosBuf.color[thePass][i] == '7') || (analGnosBuf.color[thePass][i] == '0')) {
for (j = i; j >= 0; j--) {
analGnosBuf.mark[thePass][j] = '+';
analGnosBuf.anxiety[thePass][j] = 'C';
}
analGnosBuf.anxiety[thePass][MAXPAD - 1] = 'A';
analGnosBuf.stress[thePass][i] = '3' - i;
analGnosBuf.total[thePass] += 3 - i;
}
}
/* Stick some 'x' into any holes
*/
for (i = 0; i < MAXPAD; i++)
if (analGnosBuf.mark[thePass][i] == 'x')
xFound = TRUE;
if (!xFound) {
for (i = 0; i < MAXPAD; i++) {
if (analGnosBuf.mark[thePass][i] == '=') {
analGnosBuf.mark[thePass][i] = 'x';
if (analGnosBuf.pair[thePass][i] != prDifferent) {
i++;
analGnosBuf.mark[thePass][i] = 'x';
}
return;
}
}
}
}
/* Read a value from one cell of the Analysis window
*/
void
AnalReadCell (phase, title, data)
register WORD phase;
register WORD title;
register UBYTE *data;
{
register WORD i;
WORD itemNum, kind;
Rect bounds;
Handle theItem;
Str255 itemText;
/* Retrieve the text from the dialog item
*/
GetDItem(dPtrAnal, title + (phase * analTotal), &kind, &theItem, &bounds);
GetIText(theItem, itemText);
/* Convert the data from a Str255
*/
PtoCstr((char *) itemText);
for (i = 0; i < MAXPAD; i++)
data[i] = itemText[i];
}
/* Write a value into one cell of the Analysis window
*/
void
AnalWriteCell (phase, title, data)
register WORD phase;
register WORD title;
register UBYTE *data;
{
register WORD i;
WORD itemNum, kind;
Rect bounds;
Handle theItem;
Str255 itemText;
/* Convert the data into a Str255
*/
for (i = 0; i < MAXPAD; i++)
itemText[i] = data[i];
itemText[i] = 0;
CtoPstr((char *) itemText);
/* Store the text into the dialog item
*/
GetDItem(dPtrAnal, title + (phase * analTotal), &kind, &theItem, &bounds);
SetIText(theItem, itemText);
}
/* Read edited values from the Analysis window and put them into the gnosis data
* buffer
*/
void
AnalReadWind ()
{
WORD itemNum, kind;
Rect bounds;
Handle theItem;
Str255 itemText;
long theNum;
GrafPtr savePort;
GetPort(&savePort);
SetPort(dPtrAnal);
/* Get the colors for both test passes
*/
AnalReadCell(testPass0, analColor, analGnosBuf.color[testPass0]);
AnalReadCell(testPass1, analColor, analGnosBuf.color[testPass1]);
/* Get the pairings for both test passes
*/
AnalReadCell(testPass0, analPair, analGnosBuf.pair[testPass0]);
AnalReadCell(testPass1, analPair, analGnosBuf.pair[testPass1]);
/* Get the markings for both test passes
*/
AnalReadCell(testPass0, analMark, analGnosBuf.mark[testPass0]);
AnalReadCell(testPass1, analMark, analGnosBuf.mark[testPass1]);
/* Get the anxiety for both test passes
*/
AnalReadCell(testPass0, analAnxiety, analGnosBuf.anxiety[testPass0]);
AnalReadCell(testPass1, analAnxiety, analGnosBuf.anxiety[testPass1]);
/* Get the stress for both test passes
*/
AnalReadCell(testPass0, analStress, analGnosBuf.stress[testPass0]);
AnalReadCell(testPass1, analStress, analGnosBuf.stress[testPass1]);
/* Get the total stress for both test passes
*/
GetDItem(dPtrAnal, analTotal, &kind, &theItem, &bounds);
GetIText(theItem, itemText);
StringToNum((StringPtr) itemText, &theNum);
analGnosBuf.total[testPass0] = theNum;
GetDItem(dPtrAnal, analTotal * 2, &kind, &theItem, &bounds);
GetIText(theItem, itemText);
StringToNum((StringPtr) itemText, &theNum);
analGnosBuf.total[testPass1] = theNum;
/* Get the title
*/
GetDItem(dPtrAnal, analTitle, &kind, &theItem, &bounds);
GetIText(theItem, analGnosBuf.title);
SetPort(savePort);
}
/* Write values from the gnosis data buffer into the Analysis window to allow them
* to be displayed and edited
*/
void
AnalWriteWind ()
{
WORD itemNum, kind;
Rect bounds;
Handle theItem;
long theNum;
Str255 itemText;
GrafPtr savePort;
GetPort(&savePort);
SetPort(dPtrAnal);
/* Show the colors for both test passes
*/
AnalWriteCell(testPass0, analColor, analGnosBuf.color[testPass0]);
AnalWriteCell(testPass1, analColor, analGnosBuf.color[testPass1]);
/* Show the pairings for both test passes
*/
AnalWriteCell(testPass0, analPair, analGnosBuf.pair[testPass0]);
AnalWriteCell(testPass1, analPair, analGnosBuf.pair[testPass1]);
/* Show the markings for both test passes
*/
AnalWriteCell(testPass0, analMark, analGnosBuf.mark[testPass0]);
AnalWriteCell(testPass1, analMark, analGnosBuf.mark[testPass1]);
/* Show the anxiety for both test passes
*/
AnalWriteCell(testPass0, analAnxiety, analGnosBuf.anxiety[testPass0]);
AnalWriteCell(testPass1, analAnxiety, analGnosBuf.anxiety[testPass1]);
/* Show the stress for both test passes
*/
AnalWriteCell(testPass0, analStress, analGnosBuf.stress[testPass0]);
AnalWriteCell(testPass1, analStress, analGnosBuf.stress[testPass1]);
/* Show the total stress for both test passes
*/
GetDItem(dPtrAnal, analTotal, &kind, &theItem, &bounds);
NumToString((long) analGnosBuf.total[testPass0], (StringPtr) itemText);
SetIText(theItem, itemText);
GetDItem(dPtrAnal, analTotal * 2, &kind, &theItem, &bounds);
NumToString((long) analGnosBuf.total[testPass1], (StringPtr) itemText);
SetIText(theItem, itemText);
/* Show the title
*/
GetDItem(dPtrAnal, analTitle, &kind, &theItem, &bounds);
SetIText(theItem, analGnosBuf.title);
SelIText(dPtrAnal, analTitle, 0, 255);
SetPort(savePort);
}
/* Move analysis data from the data buffer into the given prognosis record
*/
void
AnalGetBuf (gnosPtr)
register GnosPtr gnosPtr;
{
AnalReadWind();
BlockMove(&analGnosBuf, gnosPtr,
sizeof(GnosData) - sizeof(Handle) - sizeof(GnosPtr));
}
/* Move analysis data from the given prognosis record into the data buffer
*/
void
AnalPutBuf (gnosPtr)
register GnosPtr gnosPtr;
{
BlockMove(gnosPtr, &analGnosBuf,
sizeof(GnosData) - sizeof(Handle) - sizeof(GnosPtr));
AnalWriteWind();
}
/* Fill in the blanks
*/
void
AnalStub ()
{
register WORD thePass;
static char digits[] = "01234567";
static char blanks[] = " ";
/* Clear each analysis field
*/
for (thePass = testPass0; thePass <= testPass1; thePass++) {
BlockMove(digits, analGnosBuf.color[thePass], MAXPAD);
BlockMove(blanks, analGnosBuf.pair[thePass], MAXPAD);
BlockMove(blanks, analGnosBuf.mark[thePass], MAXPAD);
BlockMove(blanks, analGnosBuf.anxiety[thePass], MAXPAD);
BlockMove(blanks, analGnosBuf.stress[thePass], MAXPAD);
analGnosBuf.total[thePass] = 0;
}
if (testUser)
StrGetChooser(analGnosBuf.title);
else
GetIndString(analGnosBuf.title, RSRCBASE, strUntitled);
}
/* Report the color pair analysis
*/
void
AnalReport ()
{
/* Run the Analysis tests and report them
*/
AnalPairs();
AnalMarks(testPass0);
AnalMarks(testPass1);
AnalAngst(testPass0);
AnalAngst(testPass1);
AnalWriteWind();
WindSwitch(wPtrText, TRUE);
WindSwitch(dPtrAnal, TRUE);
}
/* Image a printed report of the Analysis window
*/
void
AnalPrint (pageRect)
register Rect *pageRect;
{
register InfoPtr infoPtr = (InfoPtr) GetWRefCon(wPtrGnos);
register WORD theLine = 2, column0, column1;
Str255 theText;
AnalReadWind();
column0 = (pageRect->left / 3 * 2) + (pageRect->right / 3);
column1 = (pageRect->left / 3) + (pageRect->right / 3 * 2);
pageRect->top += LINEHEIGHT;
MoveTo(pageRect->left, pageRect->top);
GetIndString(theText, strsAnalyze, analFile);
DrawString(theText);
DrawString(infoPtr->fileName);
GetIndString(theText, strsAnalyze, analTitle);
DrawString(theText);
DrawString(analGnosBuf.title);
pageRect->top += LINEHEIGHT * 2;
MoveTo(pageRect->left, pageRect->top);
GetIndString(theText, strsAnalyze, analColor);
DrawString(theText);
MoveTo(column0, pageRect->top);
DrawText(analGnosBuf.color[testPass0], 0, MAXPAD);
MoveTo(column1, pageRect->top);
DrawText(analGnosBuf.color[testPass1], 0, MAXPAD);
pageRect->top += LINEHEIGHT;
MoveTo(pageRect->left, pageRect->top);
GetIndString(theText, strsAnalyze, analPair);
DrawString(theText);
MoveTo(column0, pageRect->top);
DrawText(analGnosBuf.pair[testPass0], 0, MAXPAD);
MoveTo(column1, pageRect->top);
DrawText(analGnosBuf.pair[testPass1], 0, MAXPAD);
pageRect->top += LINEHEIGHT;
MoveTo(pageRect->left, pageRect->top);
GetIndString(theText, strsAnalyze, analMark);
DrawString(theText);
MoveTo(column0, pageRect->top);
DrawText(analGnosBuf.mark[testPass0], 0, MAXPAD);
MoveTo(column1, pageRect->top);
DrawText(analGnosBuf.mark[testPass1], 0, MAXPAD);
pageRect->top += LINEHEIGHT;
MoveTo(pageRect->left, pageRect->top);
GetIndString(theText, strsAnalyze, analAnxiety);
DrawString(theText);
MoveTo(column0, pageRect->top);
DrawText(analGnosBuf.anxiety[testPass0], 0, MAXPAD);
MoveTo(column1, pageRect->top);
DrawText(analGnosBuf.anxiety[testPass1], 0, MAXPAD);
pageRect->top += LINEHEIGHT;
MoveTo(pageRect->left, pageRect->top);
GetIndString(theText, strsAnalyze, analStress);
DrawString(theText);
MoveTo(column0, pageRect->top);
DrawText(analGnosBuf.stress[testPass0], 0, MAXPAD);
MoveTo(column1, pageRect->top);
DrawText(analGnosBuf.stress[testPass1], 0, MAXPAD);
pageRect->top += LINEHEIGHT;
MoveTo(pageRect->left, pageRect->top);
GetIndString(theText, strsAnalyze, analTotal);
DrawString(theText);
MoveTo(column0, pageRect->top);
NumToString((long) analGnosBuf.total[testPass0], theText);
DrawString(theText);
MoveTo(column1, pageRect->top);
NumToString((long) analGnosBuf.total[testPass1], theText);
DrawString(theText);
pageRect->top += LINEHEIGHT * 2;
}